<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="__STATIC__/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="__STATIC__/css/font.css">
    <link rel="stylesheet" href="__STATIC__/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="__STATIC__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__STATIC__/js/xadmin.js"></script>
</head>

<body>
<div class="x-body" style="padding-top: 5%">
    <form class="layui-form" id="form">
        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>列表标题
            </label>
            <div class="layui-input-inline">
                <input type="text"  name="title" required="" lay-verify="required"
                       autocomplete="off" class="layui-input" value="{$data.title}">
            </div>
        </div>
        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>图片
            </label>
            <div class="layui-input-inline">
                <button type="button" class="layui-btn" id="image">
                    <i class="layui-icon">&#xe67c;</i>选择图片
                </button>
            </div>
        </div>
        <div class="layui-form-item">
            <label  class="layui-form-label">
            </label>
            <div class="layui-input-inline" id="img">
                <img src="{$data.image}" width='300px' height='200px' alt="">
                <input type="hidden" class="shop_image" name="image" value="{$data.image}">
            </div>
        </div>

        <div class="layui-form-item" style="padding-top: 2%">
            <label class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="add" lay-submit="">
                保存
            </button>
        </div>
    </form>
</div>

<script type="text/javascript">
    layui.use(['form', 'layer','upload'], function () {
        $ = layui.jquery;
        var form = layui.form
            ,upload = layui.upload
            , layer = layui.layer;
        var uploadInst = upload.render({
            elem: '#image' //绑定元素
            ,url: '{:url("shop/shopImage")}' //上传接口
            ,done: function(res){
                $('#img').children("img").remove();
                $('#img').children(".shop_image").remove();
                $('#img').append("<img src='"+res.filename+"' width='300px' height='200px' alt='...'>");
                $('#img').append("<input class='shop_image' value='"+res.filename+"'name='image'type='hidden'>");
            }
            ,error: function(){
                //请求异常回调
            }
        });
        //监听提交
        form.on('submit(add)', function (data) {
            console.log(data.field);
            $.post('{:url("wechat/homeSave")}',data.field,function (res) {
                if (res.code == 1){
                    layer.msg(res.msg, {icon: 6,time:1000}, function () {
                        window.location.reload();
                    });
                }else {
                    layer.msg(res.msg, {icon: 5,time:1000});
                }
            });
            return false;
        });
    });
</script>
</body>

</html>
